package com.huazai.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author huazai
 * @date 2024/2/20
 */
public class ThreadDemoPool {
    public static void main(String[] args) {
        // 5个线程处理10个请求
        //final ExecutorService executorService = Executors.newFixedThreadPool(5);

        // 一个线程处理10个请求
        //final ExecutorService executorService = Executors.newSingleThreadExecutor();

        // 可扩展线程池
        final ExecutorService executorService = Executors.newCachedThreadPool();

        for (int i = 0; i < 10; i++) {
            executorService.submit(() -> {
                final String s = Thread.currentThread().getName() + "正在办理业务";
                System.out.println("s = " + s);
            });
        }
        executorService.shutdown();
    }
}
